package cn.kgc.mes.workstation.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.kgc.mes.common.annotation.Log;
import cn.kgc.mes.common.core.controller.BaseController;
import cn.kgc.mes.common.core.domain.AjaxResult;
import cn.kgc.mes.common.enums.BusinessType;
import cn.kgc.mes.workstation.domain.Workstation;
import cn.kgc.mes.workstation.service.IWorkstationService;
import cn.kgc.mes.common.utils.poi.ExcelUtil;
import cn.kgc.mes.common.core.page.TableDataInfo;

/**
 * 工作站Controller
 * 
 * @author jiyupo
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/workstation/workstation")
public class WorkstationController extends BaseController
{
    @Autowired
    private IWorkstationService workstationService;

    /**
     * 查询工作站列表
     */
//    @PreAuthorize("@ss.hasPermi('workstation:workstation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Workstation workstation)
    {
        startPage();
        List<Workstation> list = workstationService.selectWorkstationList(workstation);
        return getDataTable(list);
    }

    /**
     * 导出工作站列表
     */
//    @PreAuthorize("@ss.hasPermi('workstation:workstation:export')")
    @Log(title = "工作站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Workstation workstation)
    {
        List<Workstation> list = workstationService.selectWorkstationList(workstation);
        ExcelUtil<Workstation> util = new ExcelUtil<Workstation>(Workstation.class);
        util.exportExcel(response, list, "工作站数据");
    }

    /**
     * 获取工作站详细信息
     */
//    @PreAuthorize("@ss.hasPermi('workstation:workstation:query')")
    @GetMapping(value = "/{workstationId}")
    public AjaxResult getInfo(@PathVariable("workstationId") Long workstationId)
    {
        return success(workstationService.selectWorkstationByWorkstationId(workstationId));
    }

    /**
     * 新增工作站
     */
//    @PreAuthorize("@ss.hasPermi('workstation:workstation:add')")
    @Log(title = "工作站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workstation workstation)
    {
        return toAjax(workstationService.insertWorkstation(workstation));
    }

    /**
     * 修改工作站
     */
//    @PreAuthorize("@ss.hasPermi('workstation:workstation:edit')")
    @Log(title = "工作站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workstation workstation)
    {
        return toAjax(workstationService.updateWorkstation(workstation));
    }

    /**
     * 删除工作站
     */
//    @PreAuthorize("@ss.hasPermi('workstation:workstation:remove')")
    @Log(title = "工作站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workstationIds}")
    public AjaxResult remove(@PathVariable Long[] workstationIds)
    {
        return toAjax(workstationService.deleteWorkstationByWorkstationIds(workstationIds));
    }
}
